package com.cf.lock.controller;

import com.cf.lock.core.LockService;
import com.cf.vo.ResponseVo;
import com.cf.web.controller.PageController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * game-server-LockController
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/6/14 上午 10:28
 */
@RequestMapping("/lock")
public class LockController extends PageController {

    @Autowired
    private LockService lockService;

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET)
    public ResponseVo<List<Map>> getSystemLock() {
        List<Map> locks = lockService.getSystemLock();
        return ResponseVo.success(locks, "获取系统锁成功！");
    }

    @ResponseBody
    @RequestMapping(value = "/{key}", method = RequestMethod.DELETE)
    public ResponseVo<Boolean> release(@PathVariable("key") String key) {
        lockService.release(key);
        return ResponseVo.success(true, "取消成功！");
    }

    @Override
    protected String getPageDir() {
        return "lock";
    }
}
